home *** CD-ROM | disk | FTP | other *** search
- Path: rain.fr!world-net!usenet
- From: Frederic LACHASSE <lachass@worldnet.fr>
- Newsgroups: comp.lang.c++
- Subject: Re: function pointer in C++
- Date: Sun, 11 Feb 1996 10:19:23 +0000
- Organization: World-Net information exchange, Internet provider.
- Message-ID: <VA.0000002d.0002eabc@fred>
- References: <4f7rd5$6ha@transfer.stratus.com>
- Reply-To: lachass@worldnet.fr
- NNTP-Posting-Host: client42.sct.fr
- X-Newsreader: Virtual Access by Ashmount Research Ltd, http://www.ashmount.com
-
- I don't think there's a simple elegant solution. May be several
- templates like:
-
- template <class T1>
- struct fn1
- {
- typedef void (*ptr)(T1);
- };
-
- template <class T1, class T2>
- struct fn2
- {
- typedef void (*ptr)(T1, T2);
- };
-
- Then you can declare a void (*)(int, char **) using:
-
- fn2<int,char**>::ptr foo;
-
- (When template typedefs will be available, simpler solution)
-
- More complex template but simpler declarations
-
- template <class T1>
- class pfn1
- {
- public:
- typedef void (*pfn)(T1);
- pfn1() {}
- pfn1(pfn ptr) : _ptr(ptr) {}
- operator pfn() { return _ptr; }
- pfn operator *() { return _ptr; }
- void operator ()(T1 arg1) { _ptr(arg1); }
- pfn1<T1> &operator =(pfn ptr) { _ptr = pfn; return *this; }
- private:
- pfn _ptr;
- };
-
- template <class T1, class T2>
- class pfn2
- {
- public:
- typedef void (*pfn)(T1, T2);
- pfn2() {}
- pfn2(pfn ptr) : _ptr(ptr) {}
- operator pfn() { return _ptr; }
- pfn operator *() { return _ptr; }
- void operator ()(T1 arg1, T2 arg2) { _ptr(arg1, arg2); }
- pfn2<T1,T2> &operator =(pfn ptr) { _ptr = pfn; return *this; }
- private:
- pfn _ptr;
- };
-
- So pfn2<int,char**> will replace void (*)(int,char**)
-
- I'm not sure it's worth the effort.
-
- Frederic LACHASSE (ECP 86)
- CompuServe: 100530,2005
- Internet: lachass@worldnet.fr
-
-